package ae.pcfc.cldos.online.common.clddb.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.envers.Audited;

import ae.pcfc.cldos.online.common.domain.BaseEntity;

/**
 * Temp file storage entity
 * 
 * @author arosa
 *
 */

@Entity
@SequenceGenerator(name = "SQ_CLDOS_TEMPFILESTORE_TFSID", sequenceName = "SQ_CLDOS_TEMPFILESTORE_TFSID", initialValue = 1, allocationSize = 1)
@Table(name = "T_CLDOS_TEMP_FILE_STORAGE")
@Audited
@NamedQueries({
	@NamedQuery(name=TempFileStorage.DELETE_TRANSFERED_FILES_NAMED_QUERY_NAME, 
			query="delete from TempFileStorage where transfered=1")
})
public class TempFileStorage extends BaseEntity implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -3958382668464014359L;

	public static final String DELETE_TRANSFERED_FILES_NAMED_QUERY_NAME = "deleteAllTransfered";
	public static final String __ATTACHMENT_TYPE_CODE = "attachmentTypeCode";
	public static final String __PAYMENT_VOUCHER_DOCUMENT_TYPE_CODE = "10";
	public static final String __APPLICATION_ID = "applicationId";
	
	private Long id;
	private String fileName;
	private String fileExt;
	private Date uploadDate;
	private boolean transfered;
	private Long applicationId;
	private String attachmentTypeCode;
	
	private AppMetaData appMetaData;
	private AttachmentType attachmentType;

	
	@Id
	@GeneratedValue( strategy = GenerationType.SEQUENCE, generator="SQ_CLDOS_TEMPFILESTORE_TFSID")
	@Column(name = "TF_ID", nullable = false, precision = 30, scale = 0 )
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	
	@Column(name="TF_FILE_NAME")
	public String getFileName() {
		return fileName;
	}
	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
	
	@Column(name="TF_FILE_EXT")
	public String getFileExt() {
		return fileExt;
	}
	public void setFileExt(String fileExt) {
		this.fileExt = fileExt;
	}
	
	@Column(name="TF_UPLOAD_DATE")
	public Date getUploadDate() {
		return uploadDate;
	}
	public void setUploadDate(Date uploadDate) {
		this.uploadDate = uploadDate;
	}
	
	@Column(name="TF_TRANSFER_FLG")
	public boolean isTransfered() {
		return transfered;
	}
	public void setTransfered(boolean transfered) {
		this.transfered = transfered;
	}
	
	@Column(name="APPLICATION_ID")
	public Long getApplicationId() {
		return applicationId;
	}
	public void setApplicationId(Long applicationId) {
		this.applicationId = applicationId;
	}
	
	@Column(name="ATTACHMENT_TYPE_CODE")
	public String getAttachmentTypeCode() {
		return attachmentTypeCode;
	}
	public void setAttachmentTypeCode(String attachmentTypeCode) {
		this.attachmentTypeCode = attachmentTypeCode;
	}
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="APPLICATION_ID", referencedColumnName="APPLICATION_ID", insertable=false, updatable=false)
	public AppMetaData getAppMetaData() {
		return appMetaData;
	}
	
	public void setAppMetaData(AppMetaData appMetaData) {
		this.appMetaData = appMetaData;
	}
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="ATTACHMENT_TYPE_CODE", referencedColumnName="ATTACHMENT_TYPE_CODE", insertable=false, updatable=false)
	public AttachmentType getAttachmentType() {
		return attachmentType;
	}
	public void setAttachmentType(AttachmentType attachmentType) {
		this.attachmentType = attachmentType;
	}
	
}
